<div class="row">
    <div class="col-md-12 mgt15">
        <?php $str = $action=='update'?'Cập nhật':'Thêm mới'; ?>
        <h1 class="pull-left" style="margin-top:0;">
            <?php echo $str; ?>
            <small><?php echo $oRaoVat->getTitle(); ?></small>
        </h1>
        <div class="pull-right">
            <button type="button" class="btn btn-primary" onclick="wireOfAction('#btn-update', 'click');">
                <i class="glyphicon glyphicon-ok-sign"></i> <?php echo $str; ?>
            </button>
            <?php if($action=='update') { ?>
            <a target="_blank" class="btn btn-success" href="<?php echo page_url(RAOVAT_SLUG.'/'.$oRaoVat->getSlug()); ?>"><i class="glyphicon glyphicon-search"></i> Xem</a>
            <?php } ?>
            <a class="btn btn-default" href="<?php echo mns_page_url(RAOVAT_SLUG.'/them'); ?>"><i class="glyphicon glyphicon-plus"></i> Tạo mới</a>
            <a class="btn btn-default" href="<?php echo mns_page_url(RAOVAT_SLUG); ?>">
                <i class='glyphicon glyphicon-share-alt'></i> Trở về
            </a>
        </div>
        <div class="clearfix"></div>
        <ol class="breadcrumb mgt5">
            <li><a href="<?php echo mns_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="<?php echo mns_page_url('rao-vat'); ?>"><i class="fa fa-table"></i> Rao vặt</a></li>
            <li class="active"><i class="fa fa-file"></i> <?php echo $oRaoVat->getTitle(); ?></li>
        </ol>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <form role="form" method="post" action="<?php echo $action_link; ?>" data-callback='1'>
            <div class="form-group col-md-2">
                <?php if($oRaoVat->getImage()!=null) { ?>
                <a class="thumbnail fancybox" id="a-input-raovat-image" href="<?php echo raovat_upload($oRaoVat->getImage(), $oRaoVat->image_folder, false); ?>" title="<?php echo $oRaoVat->getTitle(); ?>">
                    <img class="media-object has-border" src="<?php echo raovat_upload($oRaoVat->getImage(), $oRaoVat->image_folder); ?>" />
                    <input type="hidden" class="form-control" id="input-raovat-image" name="raovat[image]" value="<?php echo RAOVAT_IMAGE_URL.$oRaoVat->getImage(); ?>"/>
                </a>
                <?php } else { ?>
                <a class="thumbnail fancybox" id="a-input-raovat-image" href="#" title="<?php echo $oRaoVat->getTitle(); ?>">
                    <img class="media-object has-border" data-src="holder.js/128x128/text:Hình đại diện" />
                    <input type="hidden" class="form-control" id="input-raovat-image" name="raovat[image]" />
                </a>
                <?php } ?>
                <button type="button" class="btn btn-success mgt5" id="btn-change-image" data-toggle="modal" data-backdrop="static" data-target="#modal-change-image">
                    <i class='glyphicon glyphicon-share-alt'></i> Thay đổi
                </button>
            </div>
            <div class="form-group col-md-6 col-xs-12">
                <label for="input-raovat-title">Tiêu đề</label>
                <?php $oRaoVat->setTitle($action=='insert'?'':$oRaoVat->getTitle()); ?>
                <input type="text" class="form-control auto-slug" follow-ctr='#input-raovat-slug' id="input-raovat-title" name="raovat[title]" value="<?php echo $oRaoVat->getTitle(); ?>" />
            </div>
            <div class="form-group col-md-6 col-xs-12">
                <label for="input-raovat-slug">Đường dẫn</label>
                <input type="text" class="form-control" id="input-raovat-slug" name="raovat[slug]" value="<?php echo $oRaoVat->getSlug(); ?>"/>
            </div>
            <div class="clearfix"></div>

            <div class="form-group col-md-2 col-xs-3">
                <label>
                    <input type="checkbox" name="raovat[active_flg]" value="1" <?php echo $oRaoVat->getActiveFlg()==1?"checked='checked'":""; ?> />&nbsp;Hiển thị
                </label>
            </div>
            <div class="clearfix"></div>

            <div class="col-md-2 col-xs-3">
                <label>
                    <input type="checkbox" name="raovat[delete_flg]" value="1" <?php echo $oRaoVat->getDeletedAt()!=NULL ?"checked='checked'":''; ?> />&nbsp;Xóa
                </label>
            </div>
            <div class="clearfix"></div>

            <div class="form-group col-md-4 col-xs-12">
                <label for="input-raovat-place">Nơi áp dụng</label>
                <select class="form-control" id="input-raovat-place" name="raovat[place_id]">
                    <?php foreach($aRaoVatPlace as $p) { ?>
                    <option value="<?php echo $p->getId(); ?>" <?php echo $oRaoVat->getPlaceId()==$p->getId()?"selected='selected'":"";?> >
                        <?php echo $p->getName(); ?>
                    </option>
                    <?php } ?>
                </select>
            </div>
            <div class="form-group col-md-4 col-xs-12">
                <label for="input-raovat-category">Danh mục</label>
                <select class="form-control" id="input-raovat-category" name="raovat[cate_id]">
                    <?php foreach($aRaoVatCate as $c) { ?>
                    <option value="<?php echo $c->getId(); ?>" <?php echo $oRaoVat->getCateId()==$c->getId()?"selected='selected'":"";?> >
                        <?php echo $c->getTitle(); ?>
                    </option>
                    <?php } ?>
                </select>
            </div>
            <div class="clearfix"></div>

            <div class="form-group col-md-8 col-xs-12">
                <label for="input-raovat-order">Mô tả</label>
                <textarea class="form-control" id="input-raovat-description" name="raovat[description]"><?php echo $oRaoVat->getDescription(); ?></textarea>
            </div>
            <div class="clearfix"></div>

            <div class="form-group col-md-12 col-xs-12">
                <label for="input-raovat-detail">Chi tiết</label>
                <textarea class="ckeditor" name="raovat_detail"><?php echo $oRaoVat->getDetail(); ?></textarea>
            </div>
            <div class="clearfix"></div>

            <div class="form-group col-md-12 col-xs-12">
                <?php if($action=='update') { ?>
                <input type="hidden" name="raovat_id" value="<?php echo $this->encrypt->encode($oRaoVat->getId()); ?>" />
                <?php } ?>
                <?php $str = $action=='update'?'Cập nhật':'Thêm mới'; ?>
                <button type="button" class="btn btn-success btn-submit-update" id="btn-update">
                    <i class='glyphicon glyphicon-ok-sign'></i>
                    <?php echo $str; ?>
                </button>
                <button type="button" class="btn btn-default" onclick="back();">
                    <i class='glyphicon glyphicon-share-alt'></i>
                    Trở về
                </button>
            </div>
            <div class="clearfix"></div>
        </form>
    </div>
    <div class="clearfix"></div>
</div>

<?php
$user_path       = 'public/' . $oRaoVat->image_folder .'/';
$raovat_img_path = UPLOAD_FOLDER_URL . $user_path . RAOVAT_IMAGE_URL;
$temp_img_path   = UPLOAD_FOLDER_URL . $user_path . TEMP_FOLDER_URL;
$aRaoVatImage    = upload_modal_get($raovat_img_path);
$aTempImage      = upload_modal_get($temp_img_path);
?>

<div id="modal-change-image" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalChangeImage" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Hình đại diện</h4>
            </div>
            <div class="modal-body">
                <div class="image-current">
                    <div class="row">
                        <div class="col-md-12">
                            <form class="form-horizontal" role="form" id="frm-upload-img" method="post" action="<?php echo mns_page_url('hinh-anh/tai-len'); ?>" enctype="multipart/form-data">
                                <div class="form-group">
                                    <div class="col-md-offset-2 col-md-7">
                                        <input type="file" name="userfile" class="form-control" />
                                    </div>
                                    <button id="btn-change-img" class="pull-left btn btn-primary">
                                        <i class="glyphicon glyphicon-arrow-up"></i>&nbsp;
                                        Tải lên&nbsp;
                                        <span class="hidden percent">0%</span>
                                    </button>
                                </div>
                            </form>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <p class="image-section"><i class="glyphicon glyphicon-chevron-right"></i> Đang được sử dụng</p>
                    <ul class="image-list clearPad">
                        <?php foreach($aRaoVatImage as $img) { ?>
                        <li>
                            <a href="<?php echo upload($user_path . RAOVAT_IMAGE_URL . $img, false); ?>" class="thumbnail img-block-edit raovat-img-block" data-url-remove="<?php echo admin_page_url('hinh-anh/xoa'); ?>" data-folder='<?php echo RAOVAT_IMAGE_URL; ?>' data-name='<?php echo $img; ?>'>
                                <img class="media-object" src="<?php echo upload($user_path . RAOVAT_IMAGE_URL . $img); ?>" />
                            </a>
                        </li>
                        <?php } ?>
                    </ul>
                    <ul class="image-list clearPad">
                        <li class="hidden" id="raovat-temp-block">
                            <a class="li-temp thumbnail img-block-edit raovat-img-block" data-url-remove="<?php echo admin_page_url('hinh-anh/xoa'); ?>" data-folder='<?php echo TEMP_FOLDER_URL; ?>' data-name=''>
                                <img class="media-object" />
                            </a>
                        </li>
                    </ul>
                    <p class="image-section"><i class="glyphicon glyphicon-chevron-right"></i> Đã tải lên</p>
                    <ul id="image-temp-upload" class="image-list clearPad">
                        <?php foreach($aTempImage as $img) { ?>
                        <li>
                            <a href="<?php echo temp_image($img, $oRaoVat->image_folder); ?>" class="li-temp thumbnail img-block-edit raovat-img-block" data-url-remove="<?php echo admin_page_url('hinh-anh/xoa'); ?>" data-folder='<?php echo TEMP_FOLDER_URL; ?>' data-name='<?php echo $img; ?>'>
                                <img class="media-object" src="<?php echo temp_image($img, $oRaoVat->image_folder, false, true); ?>" />
                            </a>
                        </li>
                        <?php } ?>
                    </ul>
                    <div class="clearfix"></div>
                </div>

                <div class="image-resize hidden">
                    <form id="frm-crop" method="POST" action="<?php echo admin_page_url('hinh-anh/crop'); ?>">
                        <div id="img-wrap" data-thumb-width="<?php echo POST_THUMB_W; ?>" data-screen-width="300">
                            <img src="" id="crop-target" data-ratio="<?php echo POST_THUMB_RATIO; ?>" />
                        </div>
                        <div class="inline-labels hidden">
                            <label>X1 <input type="hidden" size="4" id="x1" name="crop[x1]" /></label>
                            <label>Y1 <input type="hidden" size="4" id="y1" name="crop[y1]" /></label>
                            <label>X2 <input type="hidden" size="4" id="x2" name="crop[x2]" /></label>
                            <label>Y2 <input type="hidden" size="4" id="y2" name="crop[y2]" /></label>
                            <label>W  <input type="hidden" size="4" id="w"  name="crop[w]" /></label>
                            <label>H  <input type="hidden" size="4" id="h"  name="crop[h]" /></label>
                        </div>
                        <br />
                        <input type="hidden" id="input-crop-path" name="crop[path]" value=""/>
                        <input type="hidden" name="crop[w_case]" value="<?php echo RAOVAT_IMAGE_URL; ?>"/>
                        <button id="btn-crop" type="button" class="btn btn-success" name="submit">Cắt Hình</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>